package nc.bs.arap.bastradisc.excel;

import java.util.HashMap;
import java.util.Map;

import nc.bs.framework.common.NCLocator;
import nc.itf.uap.pf.IplatFormEntry;
import nc.pub.arap.cons.SQLConsUtil;
import nc.vo.arap.bastradisc.AggBasDiscVO;
import nc.vo.arap.bastradisc.BasDiscVO;
import nc.vo.pf.change.PfUtilBaseTools;
import nc.vo.pub.BusinessException;
import nc.vo.pub.lang.UFDateTime;
import nc.vo.pubapp.AppContext;
import nc.vo.pubapp.pflow.PfUserObject;
import nccloud.bs.excel.plugin.AbstractImportProcess;

public class BastradiscImportProcess extends AbstractImportProcess {
	
	@Override
	protected void processBill(Object obj) throws BusinessException {

		UFDateTime currtime = AppContext.getInstance().getServerTime();
		
		AggBasDiscVO bill = (AggBasDiscVO) obj;
		
		BasDiscVO headvo = bill.getParentVO();
		String cperiod = headvo.getCperiod();
		String cyear = cperiod.substring(0, 4);
		String cmonth = cperiod.substring(5, 7);
		String pk_period = SQLConsUtil.getPeriodPKByCode(cperiod);
		String transtype = headvo.getTranstype();
		String transtypepk = SQLConsUtil.getTranstypePkByCode(transtype);
		
		headvo.setPk_period(pk_period);
		headvo.setCyear(cyear);
		headvo.setCmonth(cmonth);
		headvo.setBilltype("DCH1");
		headvo.setCreationtime(currtime);
		headvo.setCreator(AppContext.getInstance().getPkUser());
		headvo.setDbilldate(currtime.getDate());
		headvo.setPk_group(AppContext.getInstance().getPkGroup());
		headvo.setTranstype(transtype);
		headvo.setTranstypepk(transtypepk);
		headvo.setApprovestatus(-1);
		
		IplatFormEntry iIplatFormEntry = (IplatFormEntry) NCLocator.getInstance()
				.lookup(IplatFormEntry.class.getName());
		
		String actionCode = "SAVEBASE";// "APPROVE";
		String billOrTranstype = "DCH1";
		HashMap eParam = new HashMap();
		eParam.put(PfUtilBaseTools.PARAM_NOTE_CHECKED, PfUtilBaseTools.PARAM_NOTE_CHECKED);
		
		iIplatFormEntry.processAction(actionCode, billOrTranstype, null, bill, initPfUserObject(), eParam);
	}
	
	private PfUserObject[] initPfUserObject() {
		PfUserObject pfo = new PfUserObject();
		Map<String, Boolean> businessCheckMap = new HashMap<String, Boolean>();
		pfo.setBusinessCheckMap(businessCheckMap);
		return new PfUserObject[] { pfo };
	}

}
